package com.freewater.springboot.demo.aop.parameter.normal;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;

@Aspect
public class AccountAspect {

    @Pointcut("execution(public * com.freewater.springboot.demo.aop.parameter.normal.AccountService.*(..))")
    public void allPublicMethod() {

    }

    @Around(value = "allPublicMethod() && args(account,..)", argNames = "joinPoint,account")
    public Object aroundAdvice(ProceedingJoinPoint joinPoint, Account account) {
        System.out.println("before ...");
        System.out.println("account: " + account);
        final Object returnVal;
        try {
            returnVal = joinPoint.proceed();
        } catch (Throwable e) {
            throw new RuntimeException(e);
        }
        System.out.println("after ...");
        return returnVal;
    }
}
